<?php
	require_once($_SERVER['DOCUMENT_ROOT']."/includes/errmess.php");
	function errorBox($string){return '<span class="messageBox error">'.$string.'</span>';}
	function successBox($string){return '<span class="messageBox success">'.$string.'</span>';}
	function infoBox($string){return '<span class="messageBox info">'.$string.'</span>';}
	function error($string){return '<span class="error">'.$string.'</span>';}
	function success($string){return '<span class="success">'.$string.'</span>';}
	function info($string){return '<span class="info">'.$string.'</span>';}
	function redirect($module="accueil",$paramsArray=array()){ 
		$params = '';
		foreach($paramsArray as $key => $value){
			$params .= '&'.$key.'='.$value;
		}
		return "<script type='text/javascript'>document.location.replace('http://".$_SERVER['SERVER_NAME']."/index.php?module=".$module.$params."');</script>";
	}
	function isConnected(){ return !empty($_SESSION['account']); }
	function checkConnection(){ if(!isConnected()){ echo redirect("accueil",array("errcode" => 1));}return isConnected();}
	function checkAdmin(){ 
		if(checkConnection()){ 
			if($_SESSION['account']->isAdmin == 0){ 
				echo redirect("accueil",array("errcode" => 1));
			}
			return ($_SESSION['account']->isAdmin == 1);
		}
		return false;
	}
	function getErrMess($id){
		switch($id){
			case 1:return errorBox(ERR_NOTCONNECTED);
			case 2:return errorBox(ERR_NOTSAMENEWPASS);
			case 3:return errorBox(ERR_INVALIDPASS);
			case 4:return successBox(OK_VALIDATEDACCOUNT);
			case 5:return errorBox(ERR_VALIDATEDACCOUNT);
			case 6:return errorBox(ERR_CONNECT);
			case 7:return successBox(OK_CONNECT);
			case 8:return errorBox(ERR_NEWMEMBER);
			case 9:return successBox(OK_NEWMEMBER);
			case 10:return errorBox(ERR_EDITMEMBER);
			case 11:return successBox(OK_EDITMEMBER);
			case 12:return errorBox(ERR_DELETEMEMBER);
			case 13:return successBox(OK_DELETEMEMBER);
			case 14:return successBox(OK_LOGOUTMEMBER);
			case 15:return successBox(OK_LOGINMEMBER);
			case 16:return errorBox(ERR_LOGINMEMBER);
			case 17:return successBox(OK_DISACTIVATEDCOLOR);
			case 18:return errorBox(ERR_DELETECOLOR);
			case 19:return successBox(OK_ACTIVATEDCOLOR);
			case 20:return successBox(OK_LOADINGRESULT);
			case 21:return successBox(ERR_LOADINGRESULT);
			case 22:return errorBox(ERR_SHORTPASS);
			case 23:return errorBox(ERR_NOTADMIN);
			case 24:return errorBox(ERR_DISABLEADMIN);
			case 25:return successBox(OK_DISABLEADMIN);
			case 26:return errorBox(ERR_NOTENOUGHADMIN);
			case 27:return errorBox(ERR_DATEFORMAT);
			case 28:return successBox(OK_DISABLEMOOD);
			case 29:return successBox(OK_ENABLEMOOD);
			case 30:return errorBox(ERR_MOODVISIBILITY);
			case 31:return successBox(OK_DISACTIVATEDSHAPE);
			case 32:return errorBox(ERR_DELETESHAPE);
			case 33:return successBox(OK_ACTIVATEDSHAPE);
			case 34:return errorBox(ERR_DELETERESULT);
			case 35:return successBox(OK_DELETERESULT);
			case 36:return error(ERR_EMPTYFIELD);
			case 37:return errorBox(ERR_EMPTYFIELD);
		}
	}
?>